<template>
	<view class="order-data-list">
		<view class="order-data-tit">{{title}}</view>
		<block v-if="orderList.length">
			<view class="order-data-item" v-for="(item,index) in orderList" :key="index">
				<view class="order-data-item-time">{{item.add_time}}</view>
				<view class="order-data-list-cell">
					<label>订单编号</label>
					<text>{{item.order_sn}}</text>
				</view>
				<view class="order-data-list-cell">
					<label>购买用户</label>
					<text v-if="item.user">{{item.user_id}}</text>
				</view>
				<view class="order-data-list-cell blue">
					<label>订单收入</label>
					<text>{{item.order_amount}}元</text>
				</view>
				<view class="order-data-list-cell">
					<label>订单利润</label>
					<text>{{item.money_p}}元</text>
				</view>
				<view class="order-data-list-cell blue">
					<label>订单类型</label>
					<text>{{item.type==1?'店铺订单':'进货订单'}}</text>
				</view>
				<view class="order-data-a" @click="goOrderInfo(item.order_id)">查看详情</view>
			</view>
			<view class="no-more" v-if="orderList.length && noMore">数据加载完毕</view>
		</block>
		<view v-else class="nothing">没有数据哦!</view>
		<pt-loading></pt-loading>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				time: '',
				title: '',
				orderList: [],
				noMore: false,
				page: 0
			};
		},
		onLoad(options) {
			if (options.time) {
				this.time = options.time
			}
			this.init()
		},
		methods: {
			init(page) {
				switch (this.time) {
					case 'today':
						this.time = 'today'
						this.title = '今日业绩'
						break;
					case 'yesterday':
						this.time = 'yesterday'
						this.title = '昨日业绩'
						break;
					case 'month':
						this.time = 'month'
						this.title = '本月业绩'
						break;
					case 'lastMonth':
						this.time = 'lastMonth'
						this.title = '上月业绩'
						break;
					case 'year':
						this.time = 'year'
						this.title = '本年业绩'
						break;
					case 'lastYear':
						this.time = 'lastYear'
						this.title = '上年业绩'
						break;
				}
				let data = {}
				if (this.time) {
					data = {
						pay_status: 2,
						parent_id: JSON.parse(uni.getStorageSync('userInfo')).user_id,
						page: page ? page : 0,
						time: this.time
					}
				} else {
					data = {
						pay_status: 2,
						parent_id: JSON.parse(uni.getStorageSync('userInfo')).user_id,
						page: page ? page : 0
					}
				}
				this.$u.apiWei.orderList(data).then(res => {
					if (res.datas.data) {
						res.datas.data.forEach(item => {
							this.orderList.push(item)
						})
					} else {
						this.noMore = true
					}
				})
			},
			goOrderInfo(order_id) {
				uni.navigateTo({
					animationDuration: 500,
					url: '/my/my-order/order-details/order-details?id=' + order_id
				})
			},
			onReachBottom() {
				if (!this.noMore) {
					this.page++
					this.init(this.page)
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F9F9F9;
	}

	.no-more {
		text-align: center;
		padding: 20rpx 0 40rpx;
		font-size: 28rpx;
		color: #999;
	}

	.nothing {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.order-data-list .order-data-tit {
		padding: 20rpx 20rpx 0;
		font-size: 36rpx;
		font-weight: bold;
	}

	.order-data-list .order-data-item .order-data-item-time {
		height: 80rpx;
		line-height: 80rpx;
		padding: 0 20rpx;
		color: #999;
		font-size: 28rpx;
	}

	.order-data-list .order-data-item .order-data-list-cell {
		background-color: #FFF;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		margin-bottom: -10rpx;
		font-size: 28rpx;
		color: #666;
	}

	.order-data-list .order-data-item .order-data-list-cell.blue {
		color: #2073F5;
	}

	.order-data-list .order-data-item .order-data-a {
		text-align: center;
		font-size: 24rpx;
		color: #2073F5;
		font-weight: bold;
		background-color: #FFF;
		padding: 30rpx 0 50rpx;
	}

	.order-data-list .order-data-item .order-data-a::after {
		content: "";
		display: inline-block;
		vertical-align: middle;
		width: 16rpx;
		height: 16rpx;
		border-right: 4rpx solid #2073F5;
		border-top: 4rpx solid #2073F5;
		transform: rotate(45deg);
		margin-top: -4rpx;
	}
</style>
